package test.in;

import org.springframework.web.bind.annotation.RequestBody;
import org.thymeleaf.spring5.util.SpringRequestUtils;
import test.flow.UserQueryFlow;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import test.annotation.ServiceMapping;
import test.context.JsonContext;
import test.covert.UserDTOCovert;
import test.covert.VoToDTOCovert;
import test.dto.CommonRspDTO;
import test.dto.UserDTO;
import test.tradeflow.EcnyTradeContext;
import test.tradeflow.TradeContext;
import test.tradeflow.TradeFlow;
import test.tradeflow.TradeFlowRuner;

import javax.servlet.http.HttpServletRequest;


/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2022/11/16 22:25
 * @ Description:
 */
@Slf4j
@Component
public class EsbIn {

    @Autowired
    private TradeFlowRuner tradeFlowRuner;
    @Autowired
    private VoToDTOCovert voToDTOCovert ;
    @ServiceMapping(path = "1d01" , channel = "esb")
    public void svc_1d01(JsonContext jsonContext) {
        log.info("1d01成功调用");
        log.info("jsonObject->{}" , jsonContext.getReqJsonObject());
        /**
         * VO转化DTO
         * */
        UserDTO userReqDTO = (UserDTO)voToDTOCovert.covert(jsonContext.getReqJsonObject(), UserDTOCovert.class);

        /**
         * todo
         * 封装公共调用
         * */
        CommonRspDTO commonRspDTO = (CommonRspDTO)tradeFlowRuner.execute(UserQueryFlow.TRADE_FLOW , EcnyTradeContext.getInstance(userReqDTO));

        jsonContext.setRspJsonObject(commonRspDTO);
    }

    @ServiceMapping(path = "1d02" , channel = "esb")
    public String svc_1d02() {
        log.info("1d02成功调用");
        return null;
    }
}
